home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5687 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  43 lines

  1. Newsgroups: comp.lang.c
  2. Path: news.sprintlink.net!news1!news
  3. From: rclark@iquest.net (Robert B. Clark)
  4. Subject: Re: gets(rec->num);  I don't know what I am doing wrong...
  5. X-Nntp-Posting-Host: ind-004-236-169.iquest.net
  6. Message-ID: <3129dbf1.656738@news.iquest.net>
  7. Sender: news@iquest.net (News Admin)
  8. Organization: IQuest Internet, Inc.
  9. X-Newsreader: Forte Agent .99d/16.182
  10. References: <4fempt$mjg@aphex.direct.ca>
  11. Date: Tue, 20 Feb 1996 15:45:00 GMT
  12.  
  13. On 9 Feb 1996 05:41:17 GMT, etoivane@direct.ca (Ed Toivanen) wrote:
  14.  
  15. >int main(void){
  16. >    char studentList[8 + 1];
  17. >    FILE * filePtr;
  18. >
  19. >    printf("Enter database file to open\n");
  20. >    while(!gets(studentList))
  21.  
  22. This is okay...
  23.  
  24. >bool addRecord(FILE* fp, STUDENT_RECORD* rec){
  25. >    printf("Student id\n");
  26. >    gets(rec->id);
  27.  
  28. ...but this not.  gets() is defined as 
  29.  
  30.     char * gets(char *s)
  31.  
  32. gets() expects a pointer to char and returns a pointer to char or EOF or
  33. NULL.
  34.  
  35. Here, you've passed an integer (the id field of the rec struct) to
  36. gets().  Either use a temporary string buffer for the gets() call and
  37. then convert to an integer or use scanf() to input an integer value
  38. directly.
  39. --
  40. Robert B. Clark <rclark@iquest.net>
  41. "Be wary of strong spirits.  It can make you shoot at tax collectors...
  42. and miss." --RAH
  43.